package com.lyf.alg.practice.huawei.hash;

import java.util.*;

/**
 * @AUTHOR LYF
 * @DATE 2022/5/26
 * @VERSION 1.0
 * @DESC
 * 1.理解匿名内部类和lambada
 * 2.熟悉Hash与HashMap
 * 3.Comparator
 *         // 1.内部类
 *         // 2.lambda:Collections.sort(list, (o1, o2) -> o1.getKey() - o2.getKey());
 *         // 3.Collections.sort(list, Comparator.comparingInt(Map.Entry::getKey));
 */
public class Hj8HashMap {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        // hashmap
        Map<Integer,Integer> map = new HashMap<>();

        for(int i=0;i<n;i++){
            Integer key = scanner.nextInt();
            Integer value = scanner.nextInt();

            Object o = map.get(key);

            if(o==null){
                map.put(key,value);
            }else{
                map.put(key,value+(Integer)o);
            }
        }

      //  LinkedList list = new LinkedList();
//        for(Map.Entry<Integer,Integer> entry:map.entrySet()){
//            System.out.println(entry.getKey()+" "+entry.getValue());
//
//        }


        List<Map.Entry<Integer,Integer>> list = map.entrySet().stream().toList();

        //Comparator.comparing())
        // 1.内部类
        // 2.lambda:Collections.sort(list, (o1, o2) -> o1.getKey() - o2.getKey());
        // 3.Collections.sort(list, Comparator.comparingInt(Map.Entry::getKey));
        Collections.sort(list, Comparator.comparingInt(Map.Entry::getKey));

//        Collections.sort

    }
}
